package com.tfswx.jcyw.tyyw.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.tfswx.jcyw.ruleenginedesigner.bean.Sjy;
import com.tfswx.jcyw.ruleenginedesigner.bean.SjysjItem;
import com.tfswx.jcyw.ruleenginedesigner.util.HttpUtil;
import com.tfswx.jcyw.tyyw.dto.WsXtMbByLibraryAndYwbmFindInputDTO;
import com.tfswx.jcyw.tyyw.dto.WsXtMbByLibraryAndYwbmFindOutputDTO;
import com.tfswx.jcyw.tyyw.dto.WsmbSjyFindInputDTO;
import com.tfswx.jcyw.tyyw.service.TyywkzService;
import com.tfswx.jcyw.tyyw.util.TyywHttpUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Ricky
 * @date 2021/6/20
 */
@Service
public class TyywkzServiceImpl implements TyywkzService {
    //    @Resource
    //    private TyywService tyywService;

    @Override
    public Sjy findWsmbSjy(WsmbSjyFindInputDTO wsmbSjyFindInputDTO) {
        WsXtMbByLibraryAndYwbmFindInputDTO wsXtMbByLibraryAndYwbmFindInputDTO = new WsXtMbByLibraryAndYwbmFindInputDTO();
        wsXtMbByLibraryAndYwbmFindInputDTO.setLibrary(wsmbSjyFindInputDTO.getLibrary());
        wsXtMbByLibraryAndYwbmFindInputDTO.setYwbm(wsmbSjyFindInputDTO.getYwbm());
        wsXtMbByLibraryAndYwbmFindInputDTO.setDwbm(wsmbSjyFindInputDTO.getDwbm());
        //        List<WsXtMbByLibraryAndYwbmFindOutputDTO> wsXtMbByLibraryAndYwbm = tyywService.findWsXtMbByLibraryAndYwbm(wsXtMbByLibraryAndYwbmFindInputDTO);

        String url = "http://" + wsmbSjyFindInputDTO.getTyywHost() + "/ws-service/api/WsXtMb/findWsXtMbByLibraryAndYwbm";
        JSONObject jsonObject = HttpUtil.postForObject(url, wsXtMbByLibraryAndYwbmFindInputDTO, JSONObject.class);

        List<WsXtMbByLibraryAndYwbmFindOutputDTO> wsXtMbByLibraryAndYwbm = TyywHttpUtil.getList(jsonObject, WsXtMbByLibraryAndYwbmFindOutputDTO.class);
        Sjy sjy = new Sjy();
        List<SjysjItem> collect = wsXtMbByLibraryAndYwbm.stream().map(item -> {
            SjysjItem sjysjItem = new SjysjItem();
            sjysjItem.setDm(item.getWsmbbh());
            sjysjItem.setFdm("");
            sjysjItem.setMc(item.getWsmbmc());
            return sjysjItem;
        }).collect(Collectors.toList());
        sjy.setObjects(collect);
        return sjy;
    }
}
